package operation;

import book.Book;
import book.BookList;

import java.util.Scanner;

public class AmendOperation implements Operation {

    @Override
    public void work(BookList bookList) {
        Scanner scanner = new Scanner(System.in);
        System.out.println("修订一本书的信息!");
        System.out.println("请输入要修改的书的名称：");
        String name = scanner.nextLine();
        Book amendBook = bookList.getBookByName(name);

        if (amendBook != null) {
            System.out.println("请输入修订后的书名：");
            String newName = scanner.nextLine();
            amendBook.setName(newName);

            System.out.println("请输入修订后的作者名：");
            String newAuthor = scanner.nextLine();
            amendBook.setAuthor(newAuthor);

            System.out.println("请输入修订后的类别：");
            String newCategory = scanner.nextLine();
            amendBook.setCategory(newCategory);

            System.out.println("请输入修订后的价格：");
            int newPrice = scanner.nextInt();
            amendBook.setPrice(newPrice);

            System.out.println("修改成功!");
        } else {
            System.out.println("没有这本书!");
        }

    }
}
